<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../../views/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>编辑服务项目</title>
<head>
	<meta charset="utf-8">
    <title>编辑服务项目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/css/btable.css" />
    
    <script type="text/javascript" src="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="/fdoctor-ms/statics/js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="/fdoctor-ms/statics/js/inputTools.js"></script>
   
</head>

<body>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;margin-left: 5px;margin-right: 5px">
	  <legend>编辑服务项目
	  </legend>
	</fieldset>
	<form class="layui-form" action="" id="dataForm">
	<input type=hidden name="updateMan" id="updateMan" value="${sessionScope.user_in_session.userName}"/>
		<div class="layui-form-item" style="width: 90%">
			<input type="hidden" id="Level" name="Level" value="${id}">
		<hr>
		</div>
		<div class="layui-btn-group">
		<button class="layui-btn layui-btn-primary layui-btn-small" id="addButton" type="button"><i class="layui-icon">&#xe654;</i>增加</button>
		</div>
		<div class="layui-form-item" style="width: 90%">
			<table class="layui-table" id="itable">
				
				<thead>
				  <tr>
				    <th style="width:30px;">序号</th>
				    <th style="width:105px;">服务项目</th>
				    <th style="width:150px;">描述</th>
				    <th style="width:85px;">频率</th>
				    <th style="width:100px;">服务类型</th>
				    <th style="width:40px;">操作</th>
				  </tr> 
				</thead>
				<tbody id="tab11">	
				</tbody>
			</table>
		</div>
		
		<hr>
	  <div align="center">
	  		<button class="layui-btn layui-btn-big layui-btn-primary layui-btn-radius" type="button" id="saveButton"><i class="layui-icon">&#xe618;</i>确认保存</button>
	  </div>
	</form>
	  
</body>

<script type="text/javascript">
	//初始化表单控件
layui.use(['jquery', 'form','laydate'], function() {
	$ = layui.jquery;
	form = layui.form();
	var laydate = layui.laydate;
	
	
	
	
	/* var detail='${detailList}';
	console.log(detail)
	var detailList=$.parseJSON(detail);
	console.log(detailList) */
	var detailList=${detailList}
 	if(detailList != "" && detailList != null){
		for(i=0; i<detailList.length;i++){
			var addlist='<tr><td><input type="text" class="layui-input" name="id" id="id" value="'+detailList[i].id+'"readOnly="true" /></td>'
			+ '				<td><input type="text" class="layui-input" name="serviceName" id="serviceName" value="'+detailList[i].serviceName+'"/></td>'
			+ '				<td><textarea  class="layui-textarea" name="serviceDetails" id="serviceDetails" >'+detailList[i].serviceDetails+'</textarea></td>'
			+ '				<td><select name="frequency" id="frequency" layer-filter="frequency">'
			+ '							<option value="-1" '
			+ ((detailList[i].frequency == "-1" ? 'selected="true"' : ''))
			+ '>总是</option>'
			+ '							<option value="1" '
			+ ((detailList[i].frequency == "1" ? 'selected="true"' : ''))
			+ '>1次/年</option>'
			+ '							<option value="2" '
			+ ((detailList[i].frequency == "2" ? 'selected="true"' : ''))
			+ '>2次/年</option>'
			+ '							<option value="4" '
			+ ((detailList[i].frequency == "4" ? 'selected="true"' : ''))
			+ '>4次/年</option>'
			+ '							<option value="6" '
			+ ((detailList[i].frequency == "6" ? 'selected="true"' : ''))
			+ '>6次/年</option>'
			+ '							<option value="6" '
			+ ((detailList[i].frequency == "12" ? 'selected="true"' : ''))
			+ '>12次/年</option>'
			+ '							<option value="24" '
			+ ((detailList[i].frequency == "24" ? 'selected="true"' : ''))
			+ '>24次/年</option>'
			+ '						</select></td>'
			+ '				<td><select name="serviceType" id="serviceType" layer-filter="serviceType">'
			+ '							<option value="1" '
			+ ((detailList[i].serviceType == "1" ? 'selected="true"' : ''))
			+ '>基础服务</option>'
			+ '							<option value="2" '
			+ ((detailList[i].serviceType == "2" ? 'selected="true"' : ''))
			+ '>增值服务</option>'
			+ '						</select></td>'
			+ '				<td><a href="javascript:void(0)"  class="deletetr" > 删除</a></td>'
			+ '					</tr>';
			$("#tab11").append(addlist);
			form.render();
		}
	}else{
		var addlist='<tr><td><input type="text" class="layui-input" name="id" id="id" value=""readOnly="true" /></td>'
		+ '				<td><input type="text" class="layui-input" name="serviceName" id="serviceName" value=""/></td>'
		+ '				<td><textarea type="" class="layui-textarea" name="serviceDetails" id="serviceDetails" ></textarea></td>'
		+ '				<td><select name="frequency" id="frequency" layer-filter="frequency">'
		+ '							<option value="-1">总是</option>'
		+ '							<option value="1">1次/年</option>'
		+ '							<option value="2">2次/年</option>'
		+ '							<option value="4">4次/年</option>'
		+ '							<option value="6">6次/年</option>'
		+ '							<option value="12">12次/年</option>'
		+ '							<option value="24">24次/年</option>'
		+ '					</select></td>'
		+ '				<td><select name="serviceType" id="serviceType" layer-filter="serviceType">'
		+ '							<option value="1">基础服务</option>'
		+ '							<option value="2">增值服务</option>'
		+ '						</select></td>'
		+ '				<td><a href="javascript:void(0)"  class="deletetr" > 删除</a></td>'
		+ '			</tr>';
		$("#tab11").append(addlist);
		form.render();
	}
	
	
	
	$('#addButton').on('click',function(){
	var addlist='<tr><td><input type="text" class="layui-input" name="id" id="id" value=""readOnly="true" /></td>'
		+ '				<td><input type="text" class="layui-input" name="serviceName" id="serviceName" value=""/></td>'
		+ '				<td><textarea type="" class="layui-textarea" name="serviceDetails" id="serviceDetails" ></textarea></td>'
		+ '				<td><select name="frequency" id="frequency" layer-filter="frequency">'
		+ '							<option value="-1">总是</option>'
		+ '							<option value="1">1次/年</option>'
		+ '							<option value="2">2次/年</option>'
		+ '							<option value="4">4次/年</option>'
		+ '							<option value="6">6次/年</option>'
		+ '							<option value="12">12次/年</option>'
		+ '							<option value="24">24次/年</option>'
		+ '					</select></td>'
		+ '				<td><select name="serviceType" id="serviceType" layer-filter="serviceType">'
		+ '							<option value="1">基础服务</option>'
		+ '							<option value="2">增值服务</option>'
		+ '						</select></td>'
		+ '				<td><a href="javascript:void(0)"  class="deletetr" > 删除</a></td>'
		+ '			</tr>';
		$("#tab11").append(addlist);
		form.render();
	
	})
	$(document).on('click', '.deletetr', function(){
  		var tr=$(this).parent().parent();
  		
  		tr.remove();
  		form.render();
	})
	
	
	
	$('#saveButton').on('click',function(){
		
    	
    	layer.confirm('确认保存？', {icon: 3, title:'提示'}, function(index){
			layer.close(index);
			$.ajax({
				type : 'POST',
				url : '/fdoctor-ms/servicePack/savePackDetail',
				data : packParams(),
				success : function(data) {
					if (data.code == 200) {
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						parent.layer.msg('保存成功！', {
							icon : 1
						});
						parent.tableConfig();
					} else {
						parent.layer.msg('保存失败！', {
							icon : 2
						});
					}
				}
			});
		});
    });
    
    function packParams(){
    	
    	var sdEntity=[];
    	var idL=$("input[name='id']");
    	var serviceNameL=$("input[name='serviceName']");
    	var serviceDetailsL=$("textarea[name='serviceDetails']");
    	var frequencyL=$("select[name='frequency']");
    	//var originalPriceL=$("input[name='originalPrice']");
    	var serviceTypeL=$("select[name='serviceType']");
    	
    	for(i=0;i<serviceNameL.length;i++){
    		var sd={};
    		if(idL[i].value!=null){
    			sd.id=idL[i].value;
    		}else{
    			sd.id="";
    		}
    		sd.serviceName=serviceNameL[i].value;
    		//sd.serviceItem=serviceItemL[i].value;
    		sd.serviceDetails=serviceDetailsL[i].value;
    		sd.frequency=frequencyL[i].value;
    		//sd.originalPrice=originalPriceL[i].value;
    		sd.serviceType=serviceTypeL[i].value;
    		sd.updateMan=$("#updateMan").val();
    		sdEntity.push(sd);
    		
    	}
    	
    	var param = {
				id:  $('#Level').val(),
				sden: JSON.stringify(sdEntity)
		}
		return param;
	}
    
   
})
</script>

</html>